    package com.travelms.controller;

    import com.travelms.service.commonuserpage.*;

    import com.travelms.dao.DBFind;
    import com.travelms.service.commonuserpage.publicchat.Client;
    import com.travelms.util.DataEffect;

    import java.io.IOException;
    import java.sql.SQLException;
    import java.util.Scanner;
    import java.util.Stack;



    public class CommonUserPage {
        public static int passwordStatus = 0;

        public CommonUserPage(String user) throws IOException, SQLException, InterruptedException {
            //普通用户界面
            //用stack来表示层级结构以便更好返回上一级
            Stack<Integer> stack = new Stack<>();
            Scanner sc = new Scanner(System.in);
            String s;//中间效验输入是否为数字
            int current = 0;//记录当前目录层级
            stack.push(current);//初始化目录层级为0

            while (true){
                if (current == 0){ //主界面
                    if (passwordStatus == 1){
                        break;
                    }
                    System.out.println("普通用户界面");
                    System.out.println("1.景点预约");
                    System.out.println("2.购买车票");
                    System.out.println("3.订购酒店");
                    System.out.println("4.公共聊天");
                    System.out.println("5.私人聊天");
                    System.out.println("6.修改个人信息");
                    System.out.println("7.查看个人信息");
                    System.out.println("8.查看购票以及预约信息");
                    System.out.println("9.账户充值");
                    System.out.println("10.退票");
                    System.out.println("11.退出登录");
                    System.out.println("-----------------");
                    while (true){
                        System.out.println("亲输入:");
                        s = sc.nextLine();
                        if (!DataEffect.isNumber(s)){//输入效验
                            System.out.println("输入错误");
                        } else if(!(Integer.parseInt(s) > 0 && Integer.parseInt(s) < 11)) {
                            System.out.println("输入错误");
                        }else {
                            current = Integer.parseInt(s);//记录输入的层级
                            stack.push(current);//压入栈
                            break;
                        }
                    }
                    if(current == 11){ //如果输入为4则退出
                        DBFind dbFind = new DBFind();
                        dbFind.removeOnlineUser(user);
                        break;
                    }



                }else if (current == 1){//为1时调用对应的界面或者是操作
                    new FindSpot(user);
                    stack.pop();
                    current = stack.peek();

                }else if (current == 2){//为2时调用对应的界面或者是操作
                    new BuyTicket(user);
                    stack.pop();
                    current = stack.peek();


                }else if (current == 3){//为3时调用对应的界面或者是操作
                    new BuyHotel(user);
                    stack.pop();
                    current = stack.peek();

                }else if (current == 4){//为3时调用对应的界面或者是操作
                    //公共聊天

                        new Client(user);

                    stack.pop();
                    current = stack.peek();

                }else if (current == 5){//为3时调用对应的界面或者是操作
                    System.out.println("后续开发中");
                    stack.pop();
                    current = stack.peek();

                }else if (current == 6){//为3时调用对应的界面或者是操作
                    //修改个人信息
                    new MopdifyOneself(user);

                    stack.pop();
                    current = stack.peek();
                }else if (current == 7){//为3时调用对应的界面或者是操作
                    //查看个人信息
                    new LookOneself(user);
                    stack.pop();
                    current = stack.peek();

                }else if (current == 8){//为3时调用对应的界面或者是操作
                    //查看购票以及预约信息
                    new LookOrderInfo(user);
                    stack.pop();
                    current = stack.peek();

                }else if (current == 9){//为3时调用对应的界面或者是操作
                    //账户充值
                    new userRecharge(user);
                    stack.pop();
                    current = stack.peek();

                }else if (current == 10){//为3时调用对应的界面或者是操作
                    //退票
                    new CancelOrder(user);
                    stack.pop();
                    current = stack.peek();

                }







            }
        }
    }


